using System;
using System.Net;
using System.Net.Sockets;

namespace monoServer
{
	public class CommunicatorSeriell : CommunicatorCommon
	{
		public CommunicatorSeriell (TcpClient c, DataManager dm, Logger l) : base(c, dm, l)
		{
			//this.sendTelegrams.addColumn("wait", typeof(bool));
			//this.sendTelegrams.disableStrictMode();
		}
		
		public void closeConnection()
		{
			this.stream.Close();
			this.client.Close();
		}
		
		public Telegram readTelegram(string telegramType, string key)
		{
			bool is_read = false;
			Telegram t = null;
			
			while(!is_read)
			{
				t = this.readSingleTelegramAsTelegram();
				if(t.type.Equals(telegramType))
				{
					if(t[0].Equals(key))
					{
						is_read = true;
					}
				}
				
				if(t.type.Equals(Telegram.ACKNOWLEDGE))
				{
					this.sendTelegrams.modifyRow("id", t[0], "ack", true);
				}
			}
			
			return t;
		}
	}
}

